# This file is part of the Net::Tube module.
#
# Net::Tube is Free Software; you can use, redistribute it and/or
# modify it under the terms of either:
#
# a) the GNU General Public License as published by the Free Software
#    Foundation, either version 2, or (at your opinion) any later
#    version, or
#
# b) the "Artistic License" which comes with Perl.
#
use strict;
use warnings;
use Test::Simple tests => 2;

use Net::Tube::Machine::Configured;

our $tconfig = 'tdata/machine_config1.xml';

sub test_new {
    my $b = Net::Tube::Machine::Configured->new();
    unless ( defined $b ) {
        return 0;
    }
    return 1;
}
ok( test_new(), "new() test" );

sub test_load_and_run_simple {
    my $m = Net::Tube::Machine::Configured->new();
    unless ( defined $m ) {
        return 0;
    }
    $m->load_pipeline($tconfig);
    
    my $tv =
"<?xml version=\"1.0\"?>\n<simple><A>foo</A><B>foo</B></simple>\n";

    my $data;
    eval { $data = $m->execute(); };
    if ($@) {
        print "# internal error: $@\n";
        return 0;
    }
    unless ( defined $data && length $data ) {
        print "tube machine generated no output\n";
        return 0;
    }
    unless ( $tv eq $data ) {
        print "# tube returned an unexpected result\n"
          . " received '$data'\n"
          . "expected '$tv'\n";    
        return 0;
    }
    
    return 1;    
}
ok(test_load_and_run_simple(), "simple load and run");

